package be.rubengerits.test;
import java.lang.reflect.*;

public class JsonObject {
	private static final String SET = "set";

	private static final String GET = "get";

	private JsonObject parent;
	
	private String name;

	public JsonObject newInstance() {
		return new JsonObject();
	}

	/*
	 * Call setter in JsonObject implementation
	 */
	public void setValue(String name, JsonObject value) throws Exception {
		String methodName = JsonUtils.constructName(SET, name);
		Method setter = this.getClass().getMethod(methodName, value.getClass());
		setter.invoke(this, value);
	}

	/*
	 * Call getter in JsonObject implementation
	 */
	public Object getvalue(String name) throws Exception {
		String methodName = JsonUtils.constructName(GET, name);

		Method getter = this.getClass().getMethod(methodName.toString());
		return getter.invoke(this);
	}

	/*
	 * Set parent object
	 */
	public void setParent(JsonObject parent) {
		this.parent = parent;
	}

	/*
	 * Get parent object
	 */
	public JsonObject getParent() {
		return parent;
	}
	
	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}
}
